package com.xxx.shetuan3.config;

import com.google.gson.Gson;
import com.xxx.shetuan3.common.CommonResult;
import com.xxx.shetuan3.common.CommonResultCode;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class My403 implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/javascript;charset=utf-8");
        Gson gson = new Gson();
        String json403 = gson.toJson(CommonResult.failed(CommonResultCode.FORBIDDEN));
        response.getWriter().print(json403);
    }
}
